<?php
/**
 * Description: 修复图片脚本
 * Created by PhpStorm.
 * User: 玉坤
 * Date: 2021/9/9
 * Time: 14:04
 */

use Biz\model\brandAccount\BrandAccountShop;

ini_set('display_errors', 1);
error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING ^ E_DEPRECATED);
ini_set('memory_limit', '1024M');

require_once '/data/wwwroot/g_vendor/autoload.php';

$start = microtime(true);
$page = 1;
$pageSize = 1000;
$lists = [];
$all_num = 0;
do {
    $limit = [($page - 1) * $pageSize, $pageSize];
    $where = [
        "LIMIT" => $limit,
        "letter[~]" => "http",
    ];
    $lists = BrandAccountShop::select(["letter", "id"], $where);

    $up_null = [];
    $up_success = [];
    foreach ($lists as $list) {
        try {
            $url = $list['letter'];
            if (strpos($url, 'Biz-imageShow') != false) {
                $newUrl = parse_url($url);
                $path = $newUrl['path'];
                $arr = explode('/', $path);
                $letter = array_pop($arr);
                $num = BrandAccountShop::update(['letter' => $letter], ['id' => $list['id']]);
            }

        } catch (\Exception $e) {
            print $e->getMessage();
//            exit();
        }
    }

    echo "无效图片数据\n";
    var_dump($up_null);
    echo "有效效图片数据\n";
    var_dump($up_success);
    $page++;
} while ($lists);

$end = microtime(true);
$time = $end - $start;
$second = round($time, 3);
var_dump('完成时间：' . date('Y-m-d H:i:s') . '   总耗时:' . $second . '秒');

